var ReportMine = function () {

    var self = this;
    this.treeId = "report_mine_tree";
    // 请求url
    this.URL = {
        ADD: '/report/datasource/add',
        TEST: '/report/datasource/connection/test',
        EDIT: '/report/datasource/edit',
        ZTREE_GET: '/report/design/tree/get'
    };

    // 树形配置
    this.treeSetting = {
        view: {
            dblClickExpand: false,
            selectedMulti: false
        },
        check: {enable: false},
        data: {simpleData: {enable: true}},
        callback: {
            onClick: function (event, treeId, treeNode) {
                self.OnLeftClick(event, treeId, treeNode)
            }
        }
    };
};

ReportMine.prototype = {
    init: function () {
        var self = this;
        $.get(this.URL.ZTREE_GET).done(function (data) {
            $.fn.zTree.init($('#' + self.treeId), self.treeSetting, data);
            self.treeObj = $.fn.zTree.getZTreeObj(self.treeId);
        });
    },
    /**
     * 树形左键事件
     * @param event 事件对象
     * @param treeId 树形id
     * @param treeNode 节点对象
     * @constructor
     */
    OnLeftClick: function (event, treeId, treeNode) {
        if (treeNode.id < 0) return;
        if (undefined !== window.reportChart) {
            // 销毁echarts实例
            window.reportChart.dispose();
            window.reportChart = undefined;
        }
        var $reportMineContent = $('#report_mine_content');
        $.xumf.ajaxAndLoading({
            method: 'get',
            url: '/report/design/render',
            data: {reportId: treeNode.id}
        }).done(function (res) {
            $reportMineContent.empty().html(res);
        });
    },
};



